module Data.Array.Extra where

import Data.Array.IArray

-- | The same as @f ! i@ (\(O(1)\) indexing) but it returns `Nothing` if @i@ is
-- not `inRange`.
infixl 9 !??
(!??) :: (Ix i, IArray a (Maybe e)) => a i (Maybe e) -> i -> Maybe e
f !?? i =
  if inRange (bounds f) i
  then f ! i
  else Nothing

